package com.ruoyi.system.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ProjectScheduleMapper;
import com.ruoyi.system.domain.ProjectSchedule;
import com.ruoyi.system.service.IProjectScheduleService;
import com.google.common.collect.Lists;
import com.ruoyi.common.core.text.Convert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 项目进度Service业务层处理
 *
 * @author zhaonz
 * @date 2023-06-08
 */
@Service
public class ProjectScheduleServiceImpl extends ServiceImpl<ProjectScheduleMapper,ProjectSchedule> implements IProjectScheduleService
{
    private static final Logger logger = LoggerFactory.getLogger(ProjectScheduleServiceImpl.class);

    @Autowired
    private ProjectScheduleMapper projectScheduleMapper;

    /**
     * 查询项目进度列表
     *
     * @param projectSchedule 项目进度
     * @return 项目进度
     */
    @Override
    public List<ProjectSchedule> list(ProjectSchedule projectSchedule)
    {
        return this.list(new QueryWrapper<>(projectSchedule));
    }

    /**
     * 查询项目进度列表
     *
     * @param projectId 项目id
     * @return 项目进度集合
     */
    @Override
    public List<ProjectSchedule> list(Long projectId) {
        MPJLambdaWrapper<ProjectSchedule> wrapper = new MPJLambdaWrapper<ProjectSchedule>()
                .selectAll(ProjectSchedule.class)
                .selectAs(SysDictData::getDictSort, ProjectSchedule::getDictSort)
                .selectAs(SysDictData::getDictLabel, ProjectSchedule::getDictLabel)
                .leftJoin(SysDictData.class, SysDictData::getDictValue, ProjectSchedule::getProjectSchedule)
                .eq("project_id", projectId)
                .eq("state", "complete");
        return this.baseMapper.selectJoinList(ProjectSchedule.class, wrapper);
    }

    /**
     * 查询项目进度
     *
     * @param scheduleId 项目进度主键
     * @return 项目进度
     */
    @Override
    public ProjectSchedule selectProjectScheduleByScheduleId(Long scheduleId)
    {
        return projectScheduleMapper.selectProjectScheduleByScheduleId(scheduleId);
    }

    /**
     * 查询项目进度列表
     *
     * @param projectSchedule 项目进度
     * @return 项目进度
     */
    @Override
    public List<ProjectSchedule> selectProjectScheduleList(ProjectSchedule projectSchedule)
    {
        return projectScheduleMapper.selectProjectScheduleList(projectSchedule);
    }

    /**
     * 新增项目进度
     *
     * @param projectSchedule 项目进度
     * @return 结果
     */
    @Override
    public int insertProjectSchedule(ProjectSchedule projectSchedule)
    {
        projectSchedule.setCreateTime(DateUtils.getNowDate());
        return projectScheduleMapper.insertProjectSchedule(projectSchedule);
    }

    /**
     * 修改项目进度
     *
     * @param projectSchedule 项目进度
     * @return 结果
     */
    @Override
    public int updateProjectSchedule(ProjectSchedule projectSchedule)
    {
        projectSchedule.setUpdateTime(DateUtils.getNowDate());
        return projectScheduleMapper.updateProjectSchedule(projectSchedule);
    }

    /**
     * 批量删除项目进度
     *
     * @param scheduleIds 需要删除的项目进度主键
     * @return 结果
     */
    @Override
    public int removeByIds(String scheduleIds)
    {
        return this.baseMapper.deleteBatchIds(Lists.newArrayList(Convert.toStrArray(scheduleIds)));
    }

    /**
     * 批量删除项目进度
     *
     * @param scheduleIds 需要删除的项目进度主键
     * @return 结果
     */
    @Override
    public int deleteProjectScheduleByScheduleIds(String scheduleIds)
    {
        return projectScheduleMapper.deleteProjectScheduleByScheduleIds(Convert.toStrArray(scheduleIds));
    }

    /**
     * 删除项目进度信息
     *
     * @param scheduleId 项目进度主键
     * @return 结果
     */
    @Override
    public int deleteProjectScheduleByScheduleId(Long scheduleId)
    {
        return projectScheduleMapper.deleteProjectScheduleByScheduleId(scheduleId);
    }
}
